﻿using System;
using System.IO;
using System.Reflection;
using System.Web;
using AnyOffice.Components;
using log4net;
namespace AnyOffice.general.file_folder
{
    public partial class uploaddisk : ModulePage
    {
        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            string str = (Request.Form["attachment_id"] == null) ? "" : Request.Form["attachment_id"].ToString();
            HttpFileCollection files = Request.Files;
            for (int i = 0; i < files.Count; i++)
            {
                HttpPostedFile file = files[i];
                if (files.GetKey(i).ToUpper() == "EDITFILE")
                {
                    try
                    {
                        str = str.Replace("../", "");
                        str = str.Replace("/", @"\");
                        string path = "/attachment/file_folder/" + HttpContext.Current.User.Identity.Name;
                        FileInfo info = new FileInfo(Server.MapPath(path) + str);
                        string name = info.Name;
                        if (info.Exists)
                        {
                            file.SaveAs(info.FullName);
                            Response.Write("文件'" + name + "'保存成功！");
                        }
                        else
                        {
                            Response.Write("文件'" + name + "'保存失败！");
                        }
                    }
                    catch (Exception exception)
                    {
                        if (log.IsErrorEnabled)
                        {
                            log.Error("", exception);
                        }
                    }
                }
            }
        }
    }
}
